package org.jeecg.modules.classrooms.rent.service.impl;

import org.jeecg.modules.classrooms.classrooms.entity.Classrooms;
import org.jeecg.modules.classrooms.classrooms.mapper.ClassroomsMapper;
import org.jeecg.modules.classrooms.rent.entity.Rent;
import org.jeecg.modules.classrooms.rent.mapper.RentMapper;
import org.jeecg.modules.classrooms.rent.service.IRentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.io.Serializable;
import java.util.Collection;

/**
 * @Description: rent
 * @Author: jeecg-boot
 * @Date:   2020-05-19
 * @Version: V1.0
 */
@Service
public class RentServiceImpl extends ServiceImpl<RentMapper, Rent> implements IRentService {

    @Autowired
    private ClassroomsMapper classroomsMapper;


    @Override
    public boolean removeByIds(Collection<? extends Serializable> idList) {
        idList.forEach(id ->{
            Rent rent = baseMapper.selectById(id);
            String classroomsId = rent.getClassroomsId();
            Classrooms classrooms = classroomsMapper.selectById(classroomsId);
            classrooms.setRentStatus("1");
            int i = classroomsMapper.updateById(classrooms);
            System.out.println(i);
            if (i>0){
                 super.removeById(id);
            }
        });

        return super.removeByIds(idList);
    }

    @Override
    public boolean removeById(Serializable id) {
        Rent rent = baseMapper.selectById(id);
        String classroomsId = rent.getClassroomsId();
        Classrooms classrooms = classroomsMapper.selectById(classroomsId);
        classrooms.setRentStatus("1");
        int i = classroomsMapper.updateById(classrooms);
        System.out.println(i);
        if (i>0){
            return super.removeById(id);
        }else {
            return false;
        }
    }
}
